package logic

import (
	"context"
	"user-profile/models/mysql"

	"user-profile/userrpc/internal/svc"
	"user-profile/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListLogic) List(in *userrpc.ListRequest) (*userrpc.ListResponse, error) {
	// todo: add your logic here and delete this line

	var user []mysql.User
	mysql.DB.Debug().Find(&user)

	var userList []*userrpc.List

	for _, m := range user {
		list := userrpc.List{
			UserId:      int64(m.ID),
			HeaderImage: m.HeaderImage,
			Name:        m.Name,
			Info:        m.Info,
		}
		userList = append(userList, &list)
	}

	return &userrpc.ListResponse{List: userList}, nil
}
